package com.cashbox.gui;

import com.cashbox.gui.componentes.CashBoxFrame;
import com.cashbox.gui.componentes.CashBoxInternalFrame;
import com.cashbox.gui.componentes.CashBoxPanel;
import com.cashbox.gui.inventario.Inventario;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import static javax.swing.Action.NAME;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

/**
 *
 * @author Gustavo Enrique Ruiz Cisneros
 */
public class Principal extends CashBoxFrame {
    private Inventario cbp = new Inventario();

    public Principal() {
        initComponents();
        generateMenu();
       // init();
    }

    private void init() {
        desktopPane.setSize(1024, 600-cashBoxMenuBar.getHeight());
    }

    private void generateMenu() {
        createMenuItems(new Inventario(), "Inventario", catalogosMenu);

    }

    private void createMenuItems(CashBoxPanel pnl, String nombre, JMenu menu) {

        JMenuItem item = new JMenuItem(new ejecutaPanel(nombre, pnl));
        menu.add(item);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new com.cashbox.gui.componentes.CashBoxDesktopPane();
        cashBoxMenuBar = new com.cashbox.gui.componentes.CashBoxMenuBar();
        archivoMenu = new javax.swing.JMenu();
        catalogosMenu = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setAutoRequestFocus(false);
        setBackground(new java.awt.Color(40, 40, 40));

        archivoMenu.setText("Archivo");
        cashBoxMenuBar.add(archivoMenu);

        catalogosMenu.setText("Catálogos");
        cashBoxMenuBar.add(catalogosMenu);

        setJMenuBar(cashBoxMenuBar);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(desktopPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 976, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(desktopPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 580, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }
//        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);

            }
        });
    }

    private class ejecutaPanel extends AbstractAction {

        private CashBoxPanel panel;
        private String nombre;

        public ejecutaPanel(String nombre, CashBoxPanel panel) {
            putValue(NAME, nombre);
            this.panel = panel;
            this.nombre = nombre;
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    CashBoxInternalFrame frame = new CashBoxInternalFrame();
                    frame.setContentPane(panel);
                    frame.pack();
                    frame.setTitle(nombre);
                    desktopPane.add(frame);
                    frame.setVisible(true);
                }
            });
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu archivoMenu;
    private com.cashbox.gui.componentes.CashBoxMenuBar cashBoxMenuBar;
    private javax.swing.JMenu catalogosMenu;
    private com.cashbox.gui.componentes.CashBoxDesktopPane desktopPane;
    // End of variables declaration//GEN-END:variables
}
